package cn.edu.java.io.writer;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

public class BufferedWriterDemo {
    public static void main(String[] args) {
        // 创建一个BufferedWriter对象，用于提供缓冲功能
        try (BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("output/file.txt"))) {

            // 写入字符流
            bufferedWriter.write("Hello, World!");
            bufferedWriter.newLine(); // 写入换行符
            bufferedWriter.write("This is a BufferedWriter example.");

            System.out.println("写入完成！");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

